package com.blog.webSocket.config;

import com.blog.Utils.CookieUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.util.List;
import java.util.Map;

/**
 * @author 任浩
 * @version 1.0
 */

@Slf4j
@Configuration
public class WebSocketConfig extends ServerEndpointConfig.Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        //获取httpsession
        Map<String, List<String>> headers = request.getHeaders();

//        HttpSession session = (HttpSession) request.getHttpSession();
        sec.getUserProperties().put("header", request.getHeaders());
        sec.getUserProperties().put("httpSession",request.getHttpSession());
    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}

